<template>
	<view>
		<u-form label-width="150rpx" style="padding: 20rpx 20rpx 20rpx 50rpx;">
			
			<u-form-item label="昵称"><u-input v-model="userName" /></u-form-item>
			<u-form-item label="帐号"><u-input v-model="phone" /></u-form-item>
			<u-form-item label="密码"><u-input v-model="passWord" /></u-form-item>
		</u-form>
		<u-row gutter="16" style="padding: 10rpx 10rpx 60rpx 10rpx;" >
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
			<u-col span="3">
				<u-button type="info" size="medium" @click="canel">返回</u-button>
			</u-col>
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
			<u-col span="3">
				<u-button type="primary" size="medium" @click="register">注册</u-button>
			</u-col>
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
		</u-row>

		
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone : "",
				passWord : "",
				userName: ""
			}
		},
		methods:{
			// 注册
			register(){
				if(this.phone === "" || this.phone === null || this.phone === undefined){
					this.$refs.uToast.show({
						title: '请输入帐号',
						type: 'error'
					});
					return;
				}
				if(this.passWord === "" || this.passWord === null || this.passWord === undefined){
					this.$refs.uToast.show({
						title: '请输入密码',
						type: 'error'
					});
					return;
				}
				this.$u.post('/ledger/member/registr', {
								userName: this.userName,
								phone: this.phone,
								passWord: this.passWord
							}).then(data => {
								if (data && data.code === 0) {
									this.$refs.uToast.show({title: "注册成功,即将跳转到登录", type: 'success',});
									setTimeout(this.canel, 1000);
								} else {
									this.$refs.uToast.show({title: data.msg, type: 'error',});
								}
							}).catch((e) => {
								this.$refs.uToast.show({title: "手机好累哦^_^", type: 'error',});
							});

			},
			// 返回我的页面
			canel(){
				this.$u.route({
					url : '/pages/my/login'
				})
			},
		}
	}
</script>